<?php get_instance()->view('common/header');?>
<style type="text/css">
    .portrait{max-width: 100%}
</style>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> <?php echo $title?></h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li class="btn-group"> <a class="btn default ml_5 return" href="<?php echo getUrl('config/postalCard');?>"><i class="fa fa-chevron-left"></i> 返回</a> </li>
                        <li> <i class="fa fa-home"></i> <a href="<?php echo getUrl('config/postalCard');?>"> 包邮卡管理  <i class="fa fa-angle-right"></i> </a></li>
                        <li><a href="javascript:;"><?php echo $title?> </a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN FORM-->
                    <form action="<?php echo getUrl('config/postalCard/save');?>" class="form-horizontal" id="model-form" method="post">
                        <div class="form-group">
                            <label class="control-label col-md-2">发放类型</label>
                            <div class="col-md-4">
                                <select name="type" class="form-control">
                                    <option <?php if(!$add && $info['type'] == 1): ?> selected <?php endif;?> value="1">注册发放</option>
                                    <option <?php if($add || $info['type'] == 2): ?> selected <?php endif;?> value="2">指定用户</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-2">名称</label>
                            <div class="col-md-4">
                                <input type="text" name="name" class="form-control required" value="<?php echo !$add ? $info['name'] : ''?>"/>
                            </div>
                            <label class="control-label col-md-2">面额</label>
                            <div class="col-md-4">
                                <input type="text" name="money" class="form-control required" value="<?php echo !$add ? $info['money'] : ''?>" placeholder="请发放面额小于100的包邮卡"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-2">可用天数</label>
                            <div class="col-md-4">
                                <input type="text" name="use_date" class="form-control required" value="<?php echo !$add ? $info['use_date'] : ''?>"/>
                            </div>
                            <label class="control-label col-md-2">每人发放数量</label>
                            <div class="col-md-4">
                                <input type="text" name="send_number" class="form-control required" value="<?php echo !$add ? $info['send_number'] : ''?>"/>
                            </div>
                        </div>
                        <div id="type1show" class="hide">
                            <div class="form-group">
                                <label class="control-label col-md-2">是否启用</label>
                                <div class="col-md-4">
                                    <select name="status" class="form-control">
                                        <option <?php if(!$add && $info['status'] == 1): ?> selected <?php endif;?> value="1">关闭</option>
                                        <option <?php if(!$add && $info['status'] == 2): ?> selected <?php endif;?> value="2">开启</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="form-actionsc fluid">
                            <div class="col-md-offset-2 col-md-9" style="padding-left:0;">
                                <input type="hidden" name="consumer_ids">
                                <input type="hidden" name="id" value="<?php echo !$add ? $info['id'] : ''?>">
                                <button class="btn green submit"><i class="fa fa-save"></i> 发送包邮卡</button>
                            </div>
                        </div>
                    </form>
                    <!-- END FORM-->
                </div>
            </div>
            <div style="height: 50px"></div>
            <div class="row table-type">
                <div class="col-md-12">
                    <div class="portlet">
                        <div class="portlet-body">
                            <div class="table-container">
                                <div class="table-actions-wrapper">
                                    <div class="help-block">温馨提示：选中状态仅作用于当前列表</div>
                                </div>
                                <table class="table table-bordered table-hover" id="datatable">
                                    <thead>
                                    <tr role="row" class="heading">
                                        <th width="50px" class="table-checkbox">
                                            <input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"/>
                                        </th>
                                        <th  width="50px" sort="false"> 头像 </th>
                                        <th sort="false">真实姓名</th>
                                        <th sort="false">昵称</th>
                                        <th sort="false">手机号码</th>
                                        <th sort="true">注册时间</th>
                                        <th sort="true">最近登录</th>
                                        <th sort="false">状态</th>
                                        <th width="100px" sort="false">操作</th>
                                    </tr>
                                    <tr>
                                        <th></th>
                                        <th></th>
                                        <th><input class="form-control form-filter input-sm" name="realname" type="text"></th>
                                        <th><input class="form-control form-filter input-sm" name="nickname" type="text"></th>
                                        <th><input class="form-control form-filter input-sm" name="mobile" type="text"></th>
                                        <th></th>
                                        <th></th>
                                        <th>
                                            <select name="status" class="form-control form-filter input-sm">
                                                <option value="0" selected>所有</option>
                                                <option value="1">禁用</option>
                                                <option value="2">启用</option>
                                            </select>
                                        </th>
                                        <th>
                                            <div class="btn-group">
                                                <a class="btn btn-xs filter-submit btn-default"><i class="fa fa-search"></i> 搜索</a>
                                                <button data-toggle="dropdown" class="btn btn-default dropdown-toggle btn-xs" type="button"><i class="fa fa-angle-down"></i></button>
                                                <ul role="menu" class="dropdown-menu pull-right">
                                                    <li><a href="javascript:void(0);" class="filter-cancel">重置</a></li>
                                                </ul>
                                            </div>
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody></tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){

        datatable_init({
            src: $("#datatable"),
            sAjaxSource: "<?php echo getUrl('config/postalCard/getConsumerList');?>",
            aoColumnDefs: [{
                'bSortable': false,
                'aTargets': [0,1,2,3,4,7,8]
            }],
            aLengthMenu : [50,100, 200, 500], //更改显示记录数选项
            iDisplayLength : 50 //默认显示的记录数
        });
        var model = $('#model-form');
        $('.submit').click(function(){
            var id =$("input[type='checkbox']:checked");
            var vl = $("[name='type']").val();
            if(id.length == 0 && vl == 2)
            {
                show_message({status:0, message:'请选择用户'});
                return false;
            }
            var consumerId = 0;
            id.each(function(){
                if (consumerId == 0){
                    consumerId = $(this).val();
                }else{
                    consumerId += ','+$(this).val();
                }
            });
            model.find('[name="consumer_ids"]').val(consumerId);
        });

        $.e_validate.init('#model-form',{successCallback:function(){
            $('[name="content"]').val('');
            $('[type="submit"]').attr('disabled', false);
            $('[type="checkbox"]').attr('checked', false).uniform();
            $("input").val('');
        }});

        $("[name='type']").on('click',function () {
            var vl = $(this).val();
            if (vl == 2){
                $(".register").addClass('hide');
                $(".table-type").removeClass('hide');
                $("#type1show").addClass('hide');
            }else if(vl == 1){
                //获取注册类包邮卡
                $.post("<?php echo getUrl('config/postalCard/getRegistPostCard');?>",function (res) {
                    if(res.status){
                        if(res.data!=null){
                            $("input[name=name]").val(res.data.name);
                            $("input[name=money]").val(res.data.money);
                            $("input[name=status]").val(res.data.status);
                            $("input[name=id]").val(res.data.id);
                            $("input[name=use_date]").val(res.data.use_date);
                        }
                    }
                },'json')
                $(".register").removeClass('hide');
                $(".table-type").addClass('hide');
                $("#type1show").removeClass('hide');
            }
        });
        $('[dp]').not("[noinit]").datepicker({
            changeMonth: true,
            autoclose: true,
            format: "yyyy-mm-dd",
            language: 'zh-CN'
        });
    });
</script>
</body>
</html>
